﻿
using Xacml.Core;
using System;
using System.Xml;

namespace Xacml.Core.Policy
{
  public class PolicySetIdReferenceElementReadWrite : XacmlElement
  {
    private string _policySetIdReference;
    private string _version;
    private string _earliestVersion;
    private string _latestVersion;

    public virtual string PolicySetId
    {
      get
      {
        return this._policySetIdReference;
      }
      set
      {
        this._policySetIdReference = value;
      }
    }

    public virtual string Version
    {
      get
      {
        return this._version;
      }
      set
      {
        this._version = value;
      }
    }

    public virtual string EarliestVersion
    {
      get
      {
        return this._earliestVersion;
      }
      set
      {
        this._earliestVersion = value;
      }
    }

    public virtual string LatestVersion
    {
      get
      {
        return this._latestVersion;
      }
      set
      {
        this._latestVersion = value;
      }
    }

    public override bool IsReadOnly
    {
      get
      {
        return false;
      }
    }

    public PolicySetIdReferenceElementReadWrite(XmlReader reader, XacmlVersion schemaVersion)
      : base(XacmlSchema.Policy, schemaVersion)
    {
      if (reader.LocalName == "PolicySetIdReference" && this.ValidateSchema(reader, schemaVersion))
      {
        if (reader.HasAttributes)
        {
          while (reader.MoveToNextAttribute())
          {
            if (reader.LocalName == "Version")
              this._version = reader.GetAttribute("Version");
            else if (reader.LocalName == "EarliestVersion")
              this._earliestVersion = reader.GetAttribute("EarliestVersion");
            else if (reader.LocalName == "LatestVersion")
              this._latestVersion = reader.GetAttribute("LatestVersion");
          }
          reader.MoveToElement();
        }
        this._policySetIdReference = reader.ReadElementString();
      }
      else
        throw new Exception(Resource.ResourceManager[Resource.MessageKey.exc_invalid_node_name, new object[1]
        {
          (object) reader.LocalName
        }]);
    }

    public PolicySetIdReferenceElementReadWrite(string policySetIdReference, string version, string earliestVersion, string lastestVersion, XacmlVersion schemaVersion)
      : base(XacmlSchema.Policy, schemaVersion)
    {
      this._policySetIdReference = policySetIdReference;
      this._version = version;
      this._earliestVersion = earliestVersion;
      this._latestVersion = lastestVersion;
    }

    public void WriteDocument(XmlWriter writer)
    {
      writer.WriteElementString("PolicySetIdReference", this._policySetIdReference);
    }
  }
}
